package com.cg.mapper;

import com.cg.entity.Category;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CategoryMapper {
    //分类列表
//    @Select("select * from category where user_id=#{userId}")
//    List<Category> categoryList(Integer userId);

    @Insert("insert into category (user_id, category_name, created_at, updated_at) VALUES (#{userId},#{categoryName},now(),now())")
    void addcategory(@Param("categoryName") String categoryName,@Param("userId")  Integer userId);

    @Update("update category set category_name=#{categoryName},updated_at=now() where category_id=#{categoryId}")
    void editcategory(Category category);

    @Select("select * from category where category_id=#{categoryId}")
    Category findCategoryById(Integer categoryId);

    @Delete("delete from category where category_id=#{categoryId}")
    void deletecategory(Integer categoryId);
    @Select("select * from category where category_name=#{categoryName} and user_id=#{userId}")
    Category findCategoryByName(@Param("categoryName")String categoryName,@Param("userId")Integer userId);

    List<Category> categoryList(@Param("userId")Integer userId,@Param("searchName") String searchName);
}
